package us.mmapp.entities;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class CommentEntity
{
	private long id;
	private long oid;
	private long uid;
	private long date;
	private String comment;
	
	public CommentEntity()
	{}
	public CommentEntity(JSONObject obj)
	{
		try
		{
			setId(obj.getLong("id"));
		} catch (JSONException e)
		{
			Log.e("COMMENT ENTITY: ", e.getMessage());
		}
		try
		{
			setOid(obj.getLong("oid"));
		} catch (JSONException e)
		{
			Log.e("COMMENT ENTITY: ", e.getMessage());
		}
		try
		{
			setUid(obj.getLong("uid"));
		} catch (JSONException e)
		{
			Log.e("COMMENT ENTITY: ", e.getMessage());
		}
		try
		{
			setDate(obj.getLong("date"));
		} catch (JSONException e)
		{
			Log.e("COMMENT ENTITY: ", e.getMessage());
		}
		try
		{
			setComment(obj.getString("comment"));
		} catch (JSONException e)
		{
			Log.e("COMMENT ENTITY: ", e.getMessage());
		}
	}
	public CommentEntity(long id1, long oid1, long uid1, long date1, String comment1)
	{
		id=id1;
		oid=oid1;
		uid=uid1;
		date=date1;
		comment=comment1;
	}
	public JSONObject toJson()
	{
		JSONObject j=new JSONObject();
		try
		{
			j.put("id", id);
			j.put("oid", oid);
			j.put("uid", uid);
			j.put("date", date);
			j.put("comment", comment);
		}
		catch(JSONException e)
		{
			
		}
		return j;
	}
	public void insertDB(SQLiteDatabase db)
	{
		ContentValues cv=new ContentValues();
		cv.put("OID", oid);
		cv.put("UID", uid);
		cv.put("TIME", date);
		cv.put("COMMENT", comment);
		
		db.insertWithOnConflict("COMMENTS", null, cv, SQLiteDatabase.CONFLICT_REPLACE);
		//db.close();
	}
	public void setId(long id)
	{
		this.id = id;
	}
	public long getId()
	{
		return id;
	}
	public void setOid(long oid)
	{
		this.oid = oid;
	}
	public long getOid()
	{
		return oid;
	}
	public void setUid(long uid)
	{
		this.uid = uid;
	}
	public long getUid()
	{
		return uid;
	}
	public void setDate(long date)
	{
		this.date = date;
	}
	public long getDate()
	{
		return date;
	}
	public void setComment(String comment)
	{
		this.comment = comment;
	}
	public String getComment()
	{
		return comment;
	}
}
